package com.zide.ams.service.impl;

import java.util.Arrays;
import java.util.List;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import com.zide.ams.domain.po.AmsArticleTag;
import com.zide.ams.domain.vo.result.AmsArticleTagResultVO;
import com.zide.ams.domain.vo.save.AmsArticleTagSaveVO;
import com.zide.ams.domain.vo.search.AmsArticleTagSearchVO;
import com.zide.ams.mapper.AmsArticleTagMapper;
import com.zide.ams.service.IAmsArticleTagService;
import com.zide.common.core.domain.PageResult;
import com.zide.common.core.vo.CommonParamIdVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 文章标签关联Service业务层处理
 * 
 * @author zide
 * @date 2024-04-29
 */
@Slf4j
@Service
public class AmsArticleTagServiceImpl implements IAmsArticleTagService {
    @Resource
    private AmsArticleTagMapper amsArticleTagMapper;

    /**
     * 查询文章标签关联列表
     */
    @Override
    public PageResult<AmsArticleTagResultVO> searchAmsArticleTagPageList(AmsArticleTagSearchVO searchVO) {
        PageResult<AmsArticleTag> dbPageResult = amsArticleTagMapper.selectPage(searchVO);
        List<AmsArticleTagResultVO> resultList = BeanUtil.copyToList(dbPageResult.getList(),AmsArticleTagResultVO.class);
        PageResult<AmsArticleTagResultVO> result = new PageResult<>();
        result.setTotal(dbPageResult.getTotal());
        result.setList(resultList);
        return result;
    }

    /**
     * 查询文章标签关联详情
     */
    @Override
    public AmsArticleTagResultVO selectAmsArticleTagById(Long id) {
            AmsArticleTag dbInfo = amsArticleTagMapper.selectById(id);
            AmsArticleTagResultVO result = BeanUtil.copyProperties(dbInfo,AmsArticleTagResultVO.class);
        return result;
    }

    /**
     * 新增文章标签关联
     */
    @Override
    public int saveAmsArticleTag(AmsArticleTagSaveVO saveVO) {
        AmsArticleTag insertBean = BeanUtil.copyProperties(saveVO,AmsArticleTag.class);
        return amsArticleTagMapper.insert(insertBean);
    }

    /**
     * 修改文章标签关联
     */
    @Override
    public int updateAmsArticleTag(AmsArticleTagSaveVO saveVO) {
        AmsArticleTag updateBean = BeanUtil.copyProperties(saveVO,AmsArticleTag.class);
        return amsArticleTagMapper.updateById(updateBean);
    }

    /**
     * 批量删除文章标签关联
     */
    @Override
    public int removeAmsArticleTagByIds(CommonParamIdVO idVO) {
        if(ArrayUtil.isNotEmpty(idVO.getIds())) {
            return amsArticleTagMapper.deleteBatchIds(Arrays.asList(idVO.getIds()));
        }else {
            return amsArticleTagMapper.deleteById(idVO.getId());
        }

    }
}
